package com.cy.cur;

import java.util.Comparator;
import java.util.concurrent.ConcurrentSkipListMap;

public class ConcurrentSkipListMap_Demo_1 {


    public static void main(String[] args) {
        ConcurrentSkipListMap<Integer, String> map = new ConcurrentSkipListMap<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1 - o2;
                // return o2 - o1;
            }
        });
        map.put(3, "Apple");
        map.put(1, "Banana");
        map.put(2, "Cherry");

        map.entrySet().forEach(
                System.out::println
        );


        // 范围查询（输出 {2=Cherry, 3=Apple}）
        System.out.println(map.subMap(1, false, 3, true));

        // 导航操作（输出 Key=2）
        // 大于等于1的最小键
        System.out.println(map.ceilingKey(1));
    }
}
